﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Collections;


/// <summary>
/// 所用用户控件的基类
/// </summary>
public class BaseUserControl:UserControl
{

    #region 属性

    public string ApplicationPath
    {
        get
        {
            string applicationPath = HttpContext.Current.Request.ApplicationPath;
            if (applicationPath == "/")
            {
                return string.Empty;
            }
            else
            {
                return applicationPath;
            }
        }
    }
   

    protected virtual string ModuleID
    {
        get
        {
            return Request["ModuleNo"];
        }
    }

    /// <summary>
    /// 是否可以新增、编辑、删除
    /// </summary>
    protected bool CanEditData
    {
        get
        {
            return true;// PermissionModules.Contains(ModuleID + "01");
        }
    }

    

    /// <summary>
    /// 是否可以浏览
    /// </summary>
    protected bool CanBrows
    {
        get
        {
            return false;
        }
    }
    

    protected ArrayList PermissionModules
    {
        get
        {
            return ((ASERIdentity)Context.User.Identity).Permits;
        }
    }

    #endregion

    #region 用户属性

    // <summary>
    // 用户帐号
    // </summary>
    //public string UserID
    //{
    //    get
    //    {
    //        return Context.User.Identity.Name;
    //    }
    //}
    /// <summary>
    /// 用户编码
    /// </summary>
    public string UserCode
    {
        get
        {
            return ((ASERIdentity)Context.User.Identity).UserCode;
        }
    }
    /// <summary>
    /// 用户姓名
    /// </summary>
    public string UserName
    {
        get
        {
            return ((ASERIdentity)Context.User.Identity).UserName;
        }
    }

    /// <summary>
    /// 用户性别
    /// </summary>
    public string Gender
    {
        get { return ((ASERIdentity)Context.User.Identity).Gender; }
    }


    /// <summary>
    /// 机构编码
    /// </summary>
    public string OrgCode
    {
        get { return ((ASERIdentity)Context.User.Identity).OrgCode; }
    }

    /// <summary>
    /// 类型编码
    /// </summary>
    public string TypeCode
    {
        get { return ((ASERIdentity)Context.User.Identity).TypeCode; }
    }

    /// <summary>
    /// 身份证号
    /// </summary>
    public string PID
    {
        get { return ((ASERIdentity)Context.User.Identity).PID; }
    }

    /// <summary>
    /// 办公电话
    /// </summary>
    public string Tel
    {
        get { return ((ASERIdentity)Context.User.Identity).Tel; }
    }

    /// <summary>
    /// 手机号码
    /// </summary>
    public string MobileNo
    {
        get { return ((ASERIdentity)Context.User.Identity).MobileNo; }
    }


    /// <summary>
    /// 用户地址
    /// </summary>
    public string Address
    {
        get { return ((ASERIdentity)Context.User.Identity).Address; }
    }

    /// <summary>
    /// 邮政编码
    /// </summary>
    public string ZipCode
    {
        get
        { return ((ASERIdentity)Context.User.Identity).ZipCode; }
    }

    /// <summary>
    /// 注册时间
    /// </summary>
    public DateTime RegDate
    {
        get
        {
            return ((ASERIdentity)Context.User.Identity).RegDate;
        }
    }

    /// <summary>
    /// 是否已更改密码
    /// </summary>
    public string IsChangePwd
    {
        get
        {
            return ((ASERIdentity)Context.User.Identity).IsChangePwd;
        }
    }

    /// <summary>
    /// 是否禁用
    /// </summary>
    public string IsForbid
    {
        get
        {
            return ((ASERIdentity)Context.User.Identity).IsForbid;
        }
    }

    /// <summary>
    /// 用户邮箱
    /// </summary>
    public string Email
    {
        get
        {
            return ((ASERIdentity)Context.User.Identity).Email;
        }

    }

    #endregion

    #region 虚方法


    public void ShowMessage(string message)
    {
        ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "Information", "alert('" + message + "')", true);
    }

   

    #endregion

    #region 私有方法

    private bool GetEditPrivilege()
    {
        return true;
    }

    /// <summary>
    /// 截取字符串方法
    /// </summary>
    /// <param name="reName"></param>
    /// <returns></returns>
    protected string CutString(object reName)
    {
        if (reName.ToString().Length > 10)
            return reName.ToString().Substring(0, 10) + "......";
        else
            return reName.ToString();
    }


    #endregion
}
